/*
 * @lc app=leetcode.cn id=198 lang=golang
 *
 * [198] 打家劫舍
 */

// @lc code=start

func rob(nums []int) int {
	n := len(nums)
	if n == 1 {
		return nums[0]
	}
	res := make([]int, n)
	res[0] = nums[0]
	res[1] = nums[1]
	r := max(res[0], res[1])
	for i := 2; i < n; i++ {
		if i < 3 {
			res[i] = res[i-2] + nums[i]
			r = max(r, res[i])
			continue
		}
		res[i] = max(res[i-2], res[i-3]) + nums[i]
		r = max(r, res[i])
	}
	return r
}
func max(i, j int) int {
	if i < j {
		return j
	}
	return i
}

// @lc code=end
